import { IsEnum, IsString, IsOptional, IsNumber, IsBoolean, IsObject } from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { SecurityEventType, SecurityLevel } from '../entities/security-log.entity';

export class CreateSecurityLogDto {
  @ApiProperty({
    description: '安全事件类型',
    enum: SecurityEventType,
  })
  @IsEnum(SecurityEventType)
  eventType: SecurityEventType;

  @ApiPropertyOptional({
    description: '安全级别',
    enum: SecurityLevel,
    default: SecurityLevel.MEDIUM,
  })
  @IsOptional()
  @IsEnum(SecurityLevel)
  securityLevel?: SecurityLevel = SecurityLevel.MEDIUM;

  @ApiProperty({
    description: '事件标题',
    maxLength: 200,
  })
  @IsString()
  eventTitle: string;

  @ApiProperty({
    description: '事件详细描述',
  })
  @IsString()
  eventDescription: string;

  @ApiPropertyOptional({
    description: '用户ID（如果涉及用户）',
  })
  @IsOptional()
  @IsString()
  userId?: string;

  @ApiPropertyOptional({
    description: '用户名（如果涉及用户）',
    maxLength: 50,
  })
  @IsOptional()
  @IsString()
  username?: string;

  @ApiPropertyOptional({
    description: 'IP地址',
    maxLength: 45,
  })
  @IsOptional()
  @IsString()
  ipAddress?: string;

  @ApiPropertyOptional({
    description: '用户代理',
  })
  @IsOptional()
  @IsString()
  userAgent?: string;

  @ApiPropertyOptional({
    description: '请求URL',
    maxLength: 500,
  })
  @IsOptional()
  @IsString()
  requestUrl?: string;

  @ApiPropertyOptional({
    description: '请求方法',
    maxLength: 10,
  })
  @IsOptional()
  @IsString()
  requestMethod?: string;

  @ApiPropertyOptional({
    description: '接口名称',
    maxLength: 100,
  })
  @IsOptional()
  @IsString()
  apiName?: string;

  @ApiPropertyOptional({
    description: '请求头信息',
  })
  @IsOptional()
  @IsObject()
  requestHeaders?: any;

  @ApiPropertyOptional({
    description: '请求体信息',
  })
  @IsOptional()
  @IsObject()
  requestBody?: any;

  @ApiPropertyOptional({
    description: '请求参数',
  })
  @IsOptional()
  @IsObject()
  requestParams?: any;

  @ApiPropertyOptional({
    description: '错误代码',
    maxLength: 50,
  })
  @IsOptional()
  @IsString()
  errorCode?: string;

  @ApiPropertyOptional({
    description: '错误信息',
  })
  @IsOptional()
  @IsString()
  errorMessage?: string;

  @ApiPropertyOptional({
    description: '堆栈跟踪',
  })
  @IsOptional()
  @IsString()
  stackTrace?: string;

  @ApiPropertyOptional({
    description: 'HTTP状态码',
  })
  @IsOptional()
  @IsNumber()
  httpStatusCode?: number;

  @ApiPropertyOptional({
    description: '响应数据',
  })
  @IsOptional()
  @IsObject()
  responseData?: any;

  @ApiPropertyOptional({
    description: '执行时间(ms)',
    default: 0,
  })
  @IsOptional()
  @IsNumber()
  executionTime?: number = 0;

  @ApiPropertyOptional({
    description: '会话ID',
    maxLength: 100,
  })
  @IsOptional()
  @IsString()
  sessionId?: string;

  @ApiPropertyOptional({
    description: '来源页面',
    maxLength: 500,
  })
  @IsOptional()
  @IsString()
  referer?: string;

  @ApiPropertyOptional({
    description: '国家/地区',
    maxLength: 50,
  })
  @IsOptional()
  @IsString()
  country?: string;

  @ApiPropertyOptional({
    description: '城市',
    maxLength: 50,
  })
  @IsOptional()
  @IsString()
  city?: string;
}
